home *** CD-ROM | disk | FTP | other *** search
- Path: lf.hp.com!gajdos
- From: gajdos@lf.hp.com (Larry Gajdos)
- Newsgroups: comp.lang.c++
- Subject: STL with VC 4.1 and namespaces
- Date: 17 Apr 1996 15:30:20 GMT
- Organization: Hewlett-Packard Little Falls Site
- Message-ID: <4l32qc$l6v@hpavua.lf.hp.com>
- NNTP-Posting-Host: gajdos@eden.lf.hp.com
- X-Newsreader: TIN [version 1.2 PL2.2]
-
- Here is yet another problem with the namespace "patch" suggested by
- Microsoft for using the STL with the foundation classes: The following
- compiles successfully (and the logic works in the larger context from
- which this was extracted) when the namespace patch is not used;
- however, it gives a compiler error when using the namespace patch.
- The code:
-
- ////////////////////////////////////////////////////////////////
- #pragma warning( disable:4786 ) // debugger symbol too large (>255 char)
- #include <new.h>
- namespace std {
- #include <bool.h>
- #include <bstring.h>
- #include <map.h>
- }
- using namespace std;
-
- class A;
- typedef string (A::*pFunc)() const;
- typedef map< string, pFunc, less<string> > FUNCMAP;
-
- class A {
- public:
- A();
- string HelloFunc() const {return "Hello!";}
- private:
- FUNCMAP* m_pMap;
- FUNCMAP::iterator m_iMap;
- };
- ////////////////////////////////////////////////////////////////
-
- The program defines a class A containing a pointer to a map of strings
- (defined using the bstring.h file included with the STL) and pointers
- to A member functions returning strings. The declaration of the iterator
- (on the second last line) leads to the following compiler errors being
- reported for the default construct line in <pair.h>:
-
- pair() : first(T1()), second(T2()) {}
- C2440: 'initializing' cannot convert from 'class std::basic_string<char>' to
- 'class std::basic_string<char> (A::*)(void)const'
- C2439: 'second': member could not be initialized
-
- Well, T2 in this case is the function pointer, so this kind of makes sense.
- But everything compiles and works _without_ the namespaces...
-
- I have found a workaround. If I redefine the pFunc typdef to refer to A
- members with no (void) return, then everything compiles:
-
- typedef void (A::*pFunc)()const;
-
- With this approach, I now need to cast assignments to the map's second
- element, for example,
-
- (*m_pMap)[ "Hello" ] = (pFunc)HelloFunc;
-
- I guess I can live with this.
-
- I would appreciate any comments!!
-
- Larry Gajdos
- not speaking for HP
-